import React, {PureComponent} from 'react'
import Device from './device-detail'
import Bar from './bar'
import Param from './param'
import Discrete from './discrete'
import Table from 'antd/lib/table'
import Log from './log'
import {connect} from 'react-redux'
import {millToString} from '../../util/util'
/*印刷机*/
class DeviceInfo extends PureComponent {
    shouldComponentUpdate(nextProps){
        console.log(nextProps.data !== this.props.data)
        return true
    }
    render() {
        const {data} = this.props
        const {logs = [], currentSingleBoard = {}, data: param = {}} = data
        const boardData = {
            '程序名': currentSingleBoard.programName,
            '任务令': currentSingleBoard.taskId,
            '编码': currentSingleBoard.encode,
            '加工时间': millToString(currentSingleBoard.processDate),
        }
        const pieData = {
            title: '设备今日运行状况',
            option: {},
            data: [{
                value: 100,
                name: '正常'
            }, {
                value: 0,
                name: '未完成'
            }, {
                value: 0,
                name: '故障'
            }]
        }


        const columns = [
            {
                title: '项目',
                dataIndex: 'project',
                key: 'project',
            }, {
                title: '数值',
                dataIndex: 'num',
                key: 'num',
            }, {
                title: '状态',
                dataIndex: 'status',
                key: 'status',
            }, {
                title: '范围',
                dataIndex: 'fw',
                key: 'address',
            }
        ];


        const params = [];

        params.push({
            project: '前刮刀压力',
            num: param.SQFRCFR + 'N',
            status: '正常',
            fw: '36~116N'
        }, {
            project: '后刮刀压力',
            num: param.SQFRCRE + 'N',
            status: '正常',
            fw: '36~116N'
        }, {
            project: '前刮刀速度',
            num: param.SQVELFW + 'mm/s',
            status: '正常',
            fw: '10~30mm/s'
        }, {
            project: '后刮刀速度',
            num: param.SQVELBK + 'mm/s',
            status: '正常',
            fw: '10~30mm/s'
        }, {
            project: '分离距离',
            num: param.SEPWAY + 'mm',
            status: '正常',
            fw: '1.2~2mm'
        }, {
            project: '分离速度',
            num: param.SEPVEL + 'mm/s',
            status: '正常',
            fw: '0.1~0.3mm/s'
        }, {
            project: '温度',
            num: param.TEMP + '℃',
            status: '正常',
            fw: '20~28℃'
        }, {
            project: '湿度',
            num: param.HUMID + '%',
            status: '正常',
            fw: '30~80%'
        })


        return (
            <Device src="../images/business/press.png" data={data} currentSingleBoard={boardData} pieData={pieData}>
                <div className="device-res">
                    <div className="device-press-info">
                        <Param columns={columns} data={params}/>
                    </div>
                    <div className="device-press-info">
                        <Log title="设备运行日志" logs={logs}/>
                    </div>
                </div>
            </Device>
        )
    }

}


function mapStoreToProps({deviceMetrics}) {
    return {
        data: deviceMetrics.get('press').toJS()
    }
}

export default connect(mapStoreToProps)(DeviceInfo)

